import { constantRoutes, asyncRoutes } from '@/router'
export default {
  namespaced: true,
  state() {
    return {
      routes: constantRoutes
    }
  },
  mutations: {
    changeRoutes(state, newroutes) {
      state.routes = [...constantRoutes, ...newroutes, { path: '*', redirect: '/404', hidden: true }]
    }
  },
  actions: {
    filterRoutes(contex, menus) {
      const routes = []
      menus.forEach(element => {
        routes.push(...asyncRoutes.filter(el => el.name === element))
      })
      contex.commit('changeRoutes', routes)
      return routes
    }
  }
}
